package javacafe.action.studybbs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javacafe.action.Action;
import javacafe.action.ActionForward;
import javacafe.dto.member.LoginInfoDTO;
import javacafe.dto.studybbs.StudyPostDTO;
import javacafe.service.StudyBBSService;
import javacafe.serviceimple.StudyBBSServiceImpl;

public class InsertPostAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		//forward
		ActionForward forward = new ActionForward();
		forward.setTiles(false);
		
		//StudyPostDTO
		StudyPostDTO dto = new StudyPostDTO();
		int sbbs_no = Integer.parseInt(request.getParameter("sbbs_no"));
		int study_no = Integer.parseInt(request.getParameter("study_no"));
		int m_no = ((LoginInfoDTO)request.getSession().getAttribute("loginInfo")).getM_no();
		String sp_title = request.getParameter("sp_title");
		String sp_content = request.getParameter("sp_content");
		dto.setSbbs_no(sbbs_no);
		dto.setStudy_no(study_no);
		dto.setSp_title(sp_title);
		dto.setSp_content(sp_content);
		dto.setM_no(m_no);
		
		//StudyBBSService
		StudyBBSService studyBBSService = StudyBBSServiceImpl.getInstance();
		studyBBSService.insertPost(dto);
		
		forward.setUrl("studybbs?command=list&study_no=" + study_no + "&sbbs_no="+ sbbs_no);
		
		return forward;
	}

}
